/**
 *  This software is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Use this application at your own risk.
 *
 *  Copyright (c) 2011 by Orfeo Morello.
 */
package com.localstreamer.mobile;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.widget.Toast;

public class Utilities 
{	
	public static void showToast(CharSequence message, Context appContext)
    {
		int duration = Toast.LENGTH_SHORT;

		Toast toast = Toast.makeText(appContext, message, duration);
		toast.show();
    }
	 
	 /**
	  * Verify is network is Available
	  * 
	  * @see http://androidadvice.blogspot.com/2010/09/check-android-network-connection-sample.html
	  * @param context
	  * @return boolean return true if the application can access the internet
	  */
	 public static boolean isNetworkAvailable(Context context) {
	     ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
	     if (connectivity != null) {
	        NetworkInfo[] info = connectivity.getAllNetworkInfo();
	        if (info != null) {
	           for (int i = 0; i < info.length; i++) {
	              if (info[i].getState() == NetworkInfo.State.CONNECTED) {
	                 return true;
	              }
	           }
	        }
	     }
	     else
	     {
	    	 Log.d("isNetworkAvailable"," connectivity is null");
	     }
	     return false;
	  }

	
}
